//
//  Two2ViewController.m
//  简单豆瓣不得不交版 1 带
//
//  Created by dllo on 16/6/24.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Two2ViewController.h"
#import "FillmTableViewCell.h"
#import "FilmModel.h"
#import "SSecondViewController.h"

static NSString *const cellActviity = @"CELL";

@interface Two2ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, retain)UITableView *myTableView;
@property(nonatomic, retain)NSMutableArray *myArray;



@end

@implementation Two2ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor magentaColor];
     self.myArray = [NSMutableArray array];
    // Do any additional setup after loading the view.

    
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 200, 44)];
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
 //   titleLabel.textColor = [UIColor blackColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"电影";
    self.navigationItem.titleView = titleLabel;
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:0.3490 green:0.6118 blue:0.6706 alpha:1.000]];
    // 设置导航栏透明度为0, 坐标从导航栏左下角 处 算 (0, 0)点 
    self.navigationController.navigationBar.translucent = NO;
    
    [self handleGata];
    [self creatTableView];

    
    
}




- (void)creatTableView {
    
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 104) style:UITableViewStylePlain];
    
  //  self.myTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myTableView];
    [_myTableView release];
    
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    
    [self.myTableView registerClass:[FillmTableViewCell class] forCellReuseIdentifier:cellActviity];
    
    
}

- (void)handleGata {
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"movielist" ofType:@".txt"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    NSArray *HXArray = [dic objectForKey:@"result"];
    for (NSDictionary *dic in HXArray) {
        
        FilmModel *model = [[FilmModel alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        [self.myArray addObject:model];
        
        
    }
    
    
}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FillmTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellActviity forIndexPath:indexPath];
    FilmModel *model = [self.myArray objectAtIndex:indexPath.row];
    cell.model = model;
    
    //  取消uitableviewcell的点以效果
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.myArray.count;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 160;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SSecondViewController *twoVC = [[SSecondViewController alloc] init];
    
    NSDictionary *dic = [self.myArray objectAtIndex:indexPath.row];
    twoVC.mytitle = [dic valueForKey:@"movieName"];

    [self.navigationController pushViewController:twoVC animated:YES];
    
    
}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
